﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:bc="clr-namespace:BreadcrumbLib.Controls"
    xmlns:conv="clr-namespace:BreadcrumbLib.Converters"
    >
  <ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="/BreadcrumbLib;component/Themes/Default/Buttons.xaml" />
    <ResourceDictionary Source="/BreadcrumbLib;component/Themes/Default/Brushes.xaml" />
	</ResourceDictionary.MergedDictionaries>

  <ControlTemplate x:Key="SwitchTemplate" TargetType="{x:Type bc:Switch}">
    <ControlTemplate.Resources>
      <conv:FlipBoolToVisibilityCollapsedConverter x:Key="fbtvc" />
      <conv:BoolToVisibilityCollapsedConverter x:Key="btvc" />
    </ControlTemplate.Resources>
    <Grid>
      <ContentPresenter Content="{TemplateBinding ContentOn}" 
                              Visibility="{Binding IsSwitchOn, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource btvc}}" />
      <ContentPresenter Content="{TemplateBinding ContentOff}" Visibility="{Binding IsSwitchOn,
                RelativeSource={RelativeSource TemplatedParent},Converter={StaticResource fbtvc}}" />
    </Grid>
  </ControlTemplate>

  <ControlTemplate x:Key="BreadcrumbSwitchTemplate" TargetType="{x:Type bc:Switch}">
    <ControlTemplate.Resources>
      <conv:BoolToVisibilityConverter x:Key="btv" />
      <conv:FlipBoolToVisibilityConverter x:Key="fbtv" />
    </ControlTemplate.Resources>

    <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
      <ToggleButton x:Name="PART_Toggle"  Grid.Column="0"  Padding="2,0" VerticalAlignment="Stretch"
                                  IsChecked="{Binding IsSwitchOn, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}" 
                                  Focusable="False"
                                  Template="{StaticResource BlankButton}" Background="Transparent" >
        <Grid>
          <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="Auto" />
          </Grid.ColumnDefinitions>


          <bc:HotTrack Grid.Column="0" 
                                 x:Name="PART_ToggleHotTrack"
                                 Width="{Binding ActualHeight, ElementName=PART_ToggleHotTrack}">
            <ContentControl ContentTemplate="{TemplateBinding HeaderTemplate}"    Content="{TemplateBinding Header}" Margin="2" />
          </bc:HotTrack>


          <Grid Grid.Column="1" Margin="2,0">
            <ContentPresenter 
                            x:Name="PART_ContentOn"
                            Content="{TemplateBinding ContentOn}" 
                            Visibility="{Binding IsSwitchOn,
                                RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource btv},Mode=OneWay}" />
            
            <ContentPresenter x:Name="PART_ContentOff"
                              Content="{TemplateBinding ContentOff}" 
                              Visibility="{Binding IsSwitchOn,
                                          RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource fbtv},Mode=OneWay}" />
          </Grid>

        </Grid>
      </ToggleButton>
    </Border>
  </ControlTemplate>

  <Style TargetType="{x:Type bc:Switch}">
    <Setter Property="Template" Value="{StaticResource SwitchTemplate}" />
    <Setter Property="Focusable" Value="False" />
  </Style>


</ResourceDictionary>